package com.huatai.datacenter.websocket;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
import org.springframework.web.socket.server.standard.ServletServerContainerFactoryBean;

/**
 * @author Lion
 * @date 2023/3/31  10:22
 */
@Configuration
@EnableWebSocket
public class WebSocketConfiguration {

	private static final int MAX_MESSAGE_SIZE = 100 * 100 * 1024;

	private static final long MAX_IDLE = 60 * 60 * 1000;

	@Bean
	public ServerEndpointExporter serverEndpointExporter(){
		return new ServerEndpointExporter();
	}
	@Bean
	public ServletServerContainerFactoryBean containerFactoryBean(){
		ServletServerContainerFactoryBean container = new ServletServerContainerFactoryBean();
		container.setMaxTextMessageBufferSize(MAX_MESSAGE_SIZE);
		container.setMaxBinaryMessageBufferSize(MAX_MESSAGE_SIZE);
		container.setMaxSessionIdleTimeout(MAX_IDLE);
		return container;
	}
}
